package ks.managers.table;

import java.util.Collection;
import java.util.Vector;

/**
 * @author Harry Moreno
 * @author Jared Razee
 */
public class TableManager {
	
	public static final int MAX = 100; /**< Number of tables. */
	protected Table[] tables = new Table[MAX]; /**< Stores tables. */
	
	/**
	 * The constructor.
	 */
	public TableManager() {
		for (int i = 0; i < MAX; i++)
			tables[i] = new Table(i+1);
	}
	
	/**
	 * Retrieves the Table with the specified id.
	 * 
	 * @param id An integer specifying the id of the table.
	 * @return The Table with the specified id.
	 */
	public Table getTable(int id){
		if(id > MAX || id < 1)
			return null;
		return tables[id-1];
	}

	/** 
	 * Retrieves a Collection containing all Tables.
	 * 
	 * @return A Collection of all Tables.
	 */
	public Collection<Table> getAllTables() {
		Vector<Table> tablesVec = new Vector<Table>(0);
		
		for (int i = 0; i < MAX; i++)
			tablesVec.add(tables[i]);
		
		return tablesVec;
	}
	
	/**
	 * Retrieves a Collection containing all active Tables. An active table is
	 * defined as a table which has at least one player at it.
	 * 
	 * @return A Collection of Tables.
	 */
	public Collection<Table> getActiveTables() {
		Vector<Table> tablesVec = new Vector<Table>(0);
		
		for (int i = 0; i < MAX; i++) {
			if(!tables[i].isEmpty())
				tablesVec.add(tables[i]);
		}
		
		return tablesVec;
	}
	
	/**
	 * updateTable()
	 * Updates the table's parameters
	 * @return the same list of tables, but with the specified one(s) updated
	 */
	/*public Table updateTable(){
		//i put this in so that it would compile. ~Daphne
		return null;
	}*/
}
